import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'

Vue.use(Vuex)

import * as job from './actions/job'
import * as auth from './actions/auth'

const store = new Vuex.Store({
    state: {
        jobs: [],
        authedmsg: "",
        token: null,
    },
    mutations: {
        jobs(state, jobs) {
            state.jobs = jobs;
            return state
        },
        authed(state, authedmsg) {
            state.authedmsg = authedmsg
            return state
        },
        token(state, token) {
            axios.interceptors.request.use(
                config => {
                    config.headers.authorization = "Bearer " + token;
                    return config
                },
                error => {
                    return Promise.reject(error)
                });

            state.token = token
            return state
        },
    },
    actions: {
        ...job,
        ...auth,

    }
});
export default store

